package controller

import (
	. "api/util"
	"net/http"
	"github.com/gin-gonic/gin"
	"path"
)

func UploadSingleFile(c *gin.Context) {
	file, err := c.FormFile("file")
	if err != nil {
		c.String(500, "上传图片出错")
	}

	dst := path.Join("./upload", file.Filename)

    c.SaveUploadedFile(file, dst)

	env := GetEnv()

	var url string
	if env == "dev" {
		url = "https://houxue158.com/images/"
	} else if env == "test" {
		url = "https://houxue158.com/images/"
	} else if env == "production" {
		url = "https://houxuetang6.cn/images/"
	}

	c.JSON(http.StatusOK, gin.H{"status": 200, "msg": "success", "data": url + file.Filename})
}

